package liuds.music;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import liuds.music.adapter.MainPagerAdapter;
import liuds.music.adapter.NewsAdapter;
import liuds.music.model.News;
import liuds.music.utils.Http;

/**
 * Created by Administrator on 2018/5/23.
 */

@SuppressLint("ValidFragment")
public class NewsFragment extends BaseFragment {

    private TabLayout tab;
    private ViewPager newsPager;
    private MainPagerAdapter newsAdapter;

    @SuppressLint("ValidFragment")
    public NewsFragment(String title) {
        super(title);
    }

    @Override
    protected void initView(Bundle state) {
        refresh.setEnabled(false);
        tab = findViewById(R.id.tab);
        newsPager = findViewById(R.id.newsPager);
        List<BaseFragment> fragments = new ArrayList<>();
        fragments.add(new NewsTypeFragment("头条","top"));
        fragments.add(new NewsTypeFragment("社会","shehui"));
        fragments.add(new NewsTypeFragment("国内","guonei"));
        fragments.add(new NewsTypeFragment("国际","guoji"));
        fragments.add(new NewsTypeFragment("娱乐","yule"));
        fragments.add(new NewsTypeFragment("体育","tiyu"));
        fragments.add(new NewsTypeFragment("军事","junshi"));
        fragments.add(new NewsTypeFragment("科技","keji"));
        fragments.add(new NewsTypeFragment("财经","caijing"));
        fragments.add(new NewsTypeFragment("时尚","shishang"));
        newsAdapter = new MainPagerAdapter(getChildFragmentManager(),fragments);
        newsPager.setAdapter(newsAdapter);
        newsPager.setOffscreenPageLimit(10);

        tab.setupWithViewPager(newsPager);
    }

    @Override
    protected int getLayoutResouceId() {
        return R.layout.fragment_news;
    }


}
